export function validPhone(str) {
  const regs = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  return regs.test(str)
}

export function validEmail(str) {
  const regs = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
  return regs.test(str)
}

export function validPassword(str) {
  const regs = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@_$!%*#?&])[A-Za-z\d$@_$!%*#?&]{6,18}$/
  return regs.test(str)
}

export const validateEmail = (rule, value, callback) => {
  if (!validEmail(value)) {
    callback(new Error('邮箱格式不正确'))
  } else {
    callback()
  }
}

export const validatePassword = (rule, value, callback) => {
  if (!validPassword(value)) {
    callback(new Error('登录密码限制为6~18个字符，至少包含1个字母、1个数字、1个特殊字符'))
  } else {
    callback()
  }
}

export const validateCaptcha = (rule, value, callback) => {
  if (value.length !== 6) {
    callback(new Error('验证码为 6 位'))
  } else {
    callback()
  }
}

export const validatePhone = (rule, value, callback) => {
  if (!validPhone(value)) {
    callback(new Error('手机号不合法'))
  } else {
    callback()
  }
}
